All Questions
10 questions
2votes
3answers
1kviews
Should classes with business logic inherit from a class with helper methods, or vise-versa?
I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the ...
2votes
1answer
288views
Selective method inheritance
I have a lot of classes that are just a CRUD interface for microservices. They only have a param for the endpoint and some of the methods get_list / get_item / create / update / delete / activate / ...
2votes
1answer
170views
Late inheritance, enforce subclass behavior in the future
A super class Transaction has two subclasses TransactionA and TransactionB. A Transaction is composed of multiple events that occur in time for a specific key (a file, a person, etc.). Depending on ...
0votes
2answers
1kviews
Should parent classes define methods using attributes of child classes?
I need to extend the parent classes of two child classes by adding shared methods to them. Starting with the initial definitions of the child classes: class ChildA(ParentA): pass class ChildB(...
0votes
1answer
84views
Classes for integrating both BitBucket and GitHub into our site (an inheritance and composition question)
I am writing a system of callbacks for BitBucket and GitHub which should modify our site on certain events in BitBucket or GitHub. It is reasonable to make a base class like GitIntegration to handle ...
54votes
5answers
40kviews
Are Python mixins an anti-pattern?
I'm fully aware that pylint and other static analysis tools are not all-knowing, and sometimes their advice must be disobeyed. (This applies for various classes of messages, not just conventions.) If ...
9votes
2answers
911views
Is Python's inheritance an "is-a" style of inheritance or a compositional style?
Given that Python allows for multiple inheritance, what does idiomatic inheritance in Python look like? In languages with single inheritance, like Java, inheritance would be used when you could say ...
2votes
2answers
755views
Python OO problem
I started learning Python yesterday and I ran into a problem. I like to hear some thoughts on it. As an exercise, I decided to build a chatserver. As part of the exercise, I wanted to write some ...
3votes
2answers
2kviews
One boilerplate class or many similar classes?
Lets say I'm trying to model a variety of objects that are virtually identical, the only difference being their class variables. Am I better off creating one boilerplate class and just calling the ...
1vote
2answers
264views
Python -- when should a class have-a rather than be-a?
This is related to "Extends is evil" vs. OCP? but separate because the idea of "implement the interface" doesn't exist in Python. I'm writing a class to pull some data off a webpage. It's ...